//
//  OosCheckingQuery.m
//  Oos4ios
//
//  Created by Pablo Gonzalez on 3/29/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import "OosCheckinQuery.h"
#import <oos4ios/ApiUrlProvider.h>


@implementation OosCheckinQuery

static NSString *const TYPE_KEY = @"type";
static NSString *const SERVICE_SLUG_KEY = @"siteSlug";
static NSString *const LATITUDE_KEY = @"latitude";
static NSString *const LONGITUDE_KEY = @"longitude";

@synthesize userSlug = mUserSlug;
@synthesize serviceSlug = mServiceSlug;

+ (OosCheckinQuery *) queryFromUserSlug:(NSString *)slug
{
	OosCheckinQuery *query = [[OosCheckinQuery alloc] autorelease];
	query.userSlug = slug;
	return query;
}

+ (OosCheckinQuery *) queryFromServiceSlug:(NSString *)slug
{
	OosCheckinQuery *query = [[OosCheckinQuery alloc] autorelease];
	query.serviceSlug = slug;
	return query;
}

- (void) setUserSlug: (NSString *) slug
{
	mUserSlug = [slug retain];
	NSString *url = [[ApiUrlProvider provider].userCheckin getUrl:slug, nil];
	[self setFeedURL: [NSURL URLWithString:url]];
    
}

- (void) setServiceSlug: (NSString *) slug
{
    mServiceSlug = [slug retain];
    NSString *url = [[ApiUrlProvider provider].serviceCheckin getUrl:slug, nil];
    [self setFeedURL: [NSURL URLWithString: url]];
}

- (NSString *) type
{
	return [self valueForParameterWithName: TYPE_KEY];
}

- (void) setType:(NSString *) type
{
	[self addCustomParameterWithName:TYPE_KEY value:type];
}

- (NSString *)latitude
{
    return [self valueForParameterWithName: LATITUDE_KEY];
}

- (void)setLatitude:(NSString *)latitude
{
    [self addCustomParameterWithName:LATITUDE_KEY value:latitude];
}

- (NSString *)longitude
{
    return [self valueForParameterWithName:LONGITUDE_KEY];
}

- (void)setLongitude:(NSString *)longitude
{
    [self addCustomParameterWithName:LONGITUDE_KEY value:longitude];
}

- (void)setCreateServiceSlug:(NSString *)createServiceSlug
{
    [self addCustomParameterWithName:SERVICE_SLUG_KEY value:createServiceSlug];
}

- (NSString *)createServiceSlug
{
    return [self valueForParameterWithName:SERVICE_SLUG_KEY];
}

- (void) packStore:(OosOptionsStore *)store
{
	[super packStore:store];
    OosCheckinOptions *checkinOptions = store.checkinOptions;
    self.createServiceSlug = checkinOptions.siteSlug;
    self.latitude = checkinOptions.latitude;
    self.longitude = checkinOptions.longitude;
    self.type = checkinOptions.type;
}

- (void) dealloc
{
	[mUserSlug release];
	[mServiceSlug release];
	[super dealloc];
}

@end
